home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DICLOSE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-19
|
4KB
|
147 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: diclose.c
// Title: Data File I/O Library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains code to close data files.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <di.h>
//----------------------------------------------------------------------------
// Description: Close all open files
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioCloseAll(void)
{
HPF hpf;
BOOL fResult = TRUE;
for (hpf = 0; hpf < MAX_PHYSICAL_FILES; ++hpf)
if (di.physical[hpf].fUsed && !DioClosePhysical(hpf))
fResult = FALSE;
if (!DioSetDataPath(NULL))
fResult = FALSE;
return fResult;
}
//----------------------------------------------------------------------------
// Description: Close logical file
// Parameters: hlf Logical file handle
// If handle is invalid, the function returns success.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioCloseLogical(HLF hlf)
{
BOOL fResult = TRUE;
if (hlf < 0
|| hlf >= MAX_LOGICAL_FILES
|| !di.logical[hlf].fUsed)
return TRUE;
DioCacheRelease(hlf);
if (di.logical[hlf].hlfNext >= 0)
if (!DioCloseLogical(di.logical[hlf].hlfNext))
fResult = FALSE;
memset(&di.logical[hlf], 0, sizeof(di.logical[hlf]));
di.cLogical--;
return fResult;
}
//----------------------------------------------------------------------------
// Description: Close physical file.
// Parameters: hpf Physical file handle
// If handle is invalid, the function returns success.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioClosePhysical(HPF hpf)
{
HLF hlf;
BOOL fResult = TRUE;
if (hpf < 0 // Is file open?
|| hpf >= MAX_PHYSICAL_FILES
|| !di.physical[hpf].fUsed)
return FALSE;
// Close all associated logical files
for (hlf = 0; hlf < MAX_LOGICAL_FILES; ++hlf)
if (di.logical[hlf].fUsed
&& di.logical[hlf].hpf == hpf
&& !DioCloseLogical(hlf))
fResult = FALSE;
// Close physical file
if (!FileClose(di.physical[hpf].hf))
fResult = FALSE;
if (di.physical[hpf].pdatadir)
MemFree(di.physical[hpf].pdatadir);
if (di.physical[hpf].pdatahdr)
MemFree(di.physical[hpf].pdatahdr);
// Clear entry
memset(&di.physical[hpf], 0, sizeof(di.physical[hpf]));
di.cPhysical--;
return fResult;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioRelease(void)
{
BOOL fResult = DioDirReleaseAll();
if (DioHeaderReleaseAll())
fResult = FALSE;
return fResult;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------